<?php

class Model_Orm_Order extends \Orm\Model
{
        protected static $_primary_key = array('id');
	protected static $_properties = array(
		'id',
		'show_id',
		'user_id',
                'first_name',
                'last_name',
                'phone_nr',
                'email',
		'is_paid',
		'purchase_time'
	);

	protected static $_table_name = 'orders';

    protected static $_belongs_to = array(
	'show' => array(
	    'key_from' => 'show_id',
	    'model_to' => 'Model_Orm_Show',
	    'key_to' => 'id')
    );
    
    protected static $_has_many = array(
	'reservations' => array(
	    'key_from' => 'id',
	    'model_to' => 'Model_Orm_Reservation',
	    'key_to' => 'order_id',
	    'cascade_save' => true,
	    'cascade_delete' => false)
    );
    
    public static function validate($factory) {
        $val = Validation::forge($factory);
        
        $val->add_field('First_name', 'Vārds', 'required|max_length[30]|min_length[2]');
        $val->add_field('Last_name', 'Uzvārds', 'required|max_length[30]|min_length[2]');
        $val->add_field('Email', 'E-pasta adrese', 'required|max_length[255]|min_length[3]');
        $val->add_field('Phone', 'Telefona numurs', 'max_length[25]|min_length[4]');
        
        return $val;
    }
}